<?php
/**
Version 0.1
SEMF - Web Desiging Framework for Sport Event Managment
Copyright (C) 2006, SEMF Developers

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

*/


// this will generate the script + html + php per component..
function generate_component($container, $doc, $script_handler, $html_properties, $semf_root)
{
	$component = $container->firstChild;
	$result_html = NULL;
	if ( $component != NULL ) //Not always containers have components..
	{
		$component_name = $component->getAttribute('type');
		$component_id = $component->getAttribute('id');

		$xslt_file = $semf_root."page_designer/components/${component_name}/editor_gen.xsl";

		$xml_str = $doc->saveXML($component);
		$doc2 = new DOMDocument();
		$doc2 ->loadXML( $xml_str);
		
		$xslt = new xsltProcessor;
		$xslt->importStyleSheet(DomDocument::load($xslt_file));
		
		$result_html = $xslt->transformToDoc($doc2);
		
		$child_containers = $component->childNodes;
		
		/** parse the properites  */
		$properties = load_properties($component);
		$script_handler->parse_properties($component_name, $component_id,
		                                  $component, $properties);
										
		// load important properties..  
		$comp_class_name = ${component_name}."Component";
		$obj = new ${comp_class_name}();
		
		$html_properties = $obj->load_html_properties($properties, $html_properties);
				
		foreach ($child_containers as $child_container)
		{
			if ($child_container->tagName != "container" )
			{
				continue;
			}
			$id = $child_container->getAttribute('id');
			$html_container = $result_html->getElementById($id); //it is inside result..
			$generate_result = generate_component($child_container, $doc, $script_handler, $html_properties, $semf_root);
			
			$html_properties = $generate_result[1];
			$child_html = $generate_result[0];
						
			if ( $child_html != NULL )
			{
				appendNode($html_container, $child_html->documentElement, $result_html );
				// from  "util/dom.php"
				
			}
		}	
	}
	return array($result_html, $html_properties);
}

?>
